package cn.m3a1.control;

import cn.m3a1.bean.Employee;
import cn.m3a1.server.EmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by wyj on 2019-04-14.
 */
@Controller
public class EmployeeController {
    @Resource(name = "employeeService")
    EmployeeService employeeService;
    @RequestMapping("/emps")
    public String getEmloyee(@RequestParam(value ="pn",defaultValue = "1")Integer pn, Model model){//分页查询员工数据
        PageHelper.startPage(pn,5);
        //startpage紧跟的查询就是分页查询
       List<Employee> list= employeeService.getall();
        PageInfo pageInfo=new PageInfo(list,5);//将查询到的结果交给pageInfo,连续显示5个页面的页码
        model.addAttribute("page",pageInfo);
        return "list.jsp";
    }
}
